<script setup>
  import { onLaunch, onShow, onError, onHide, onUnload } from '@dcloudio/uni-app';
  import { ShoproInit } from './sheep';
  import sheep from '@/sheep';
  import { computed } from 'vue';
  import { closeAuthModal } from '@/sheep/hooks/useModal';
  // #ifndef MP-WEIXIN
  onLaunch(async (options) => {
    // #endif
    // #ifdef MP-WEIXIN
    onLaunch(async () => {
      // #endif
      // #ifdef H5
      let currentMode = uni.getStorageSync('currentMode');
      if (options.path != 'pages/public/richtext' || options.path != '/pages/genealogy/management') {
        if (uni.getSystemInfoSync().windowWidth > 960) {
          let pcStore = uni.getStorageSync('pc-store') ? JSON.parse(uni.getStorageSync('pc-store')) : '';
          if (!!pcStore && pcStore.sidebarOptions != 0) {
            sheep.$store('pc').setSidebarOptions(pcStore.sidebarOptions);
          } else {
            sheep.$store('pc').setSidebarOptions(0);
          }
          if (!!pcStore && pcStore.sidebarCulture != 0) {
            sheep.$store('pc').setSidebarCulture(pcStore.sidebarCulture);
          } else {
            sheep.$store('pc').setSidebarCulture(0);
          }
          if (!currentMode) {
            uni.setStorageSync('currentMode', 'PC');
            uni.redirectTo({
              url: '/pages/message/startupPage',
            });
          }
          if (currentMode != 'PC') {
            uni.setStorageSync('currentMode', 'PC');
            uni.redirectTo({
              url: '/pages/message/startupPage',
            });
          }
        } else {
          if (!currentMode) {
            uni.setStorageSync('currentMode', 'H5');
            uni.redirectTo({
              url: '/pages/message/startupPage',
            });
          }
          if (currentMode != 'H5') {
            uni.setStorageSync('currentMode', 'H5');
            uni.redirectTo({
              url: '/pages/message/startupPage',
            });
          }
        }
      }

      // #endif
      sheep.$store('app').ingotFlag = false;
      // 获取当前更新的版本号
      await sheep.$store('AI').updateEdition();
      // 条件编辑只在微信小程序显示
      // #ifdef MP-WEIXIN
      const accountInfo = wx.getAccountInfoSync();
      const version_number = accountInfo.miniProgram.envVersion; // 小程序 版本号
      sheep.$store('AI').setVersion(version_number);
      // #endif

      closeAuthModal();
      // 隐藏原生导航栏 使用自定义底部导航
      uni.hideTabBar({
        fail: () => {
        },
      });
      // 获取设备信息
      sheep.$store('system_info').setSystemInfo();

      // 加载Shopro底层依赖
      await ShoproInit();


      sheep.$store('AI').setAllAIList();

      const isLogin = computed(() => sheep.$store('user').isLogin);
      if (!!isLogin.value) {
        await sheep.$store('AI').setAllSessionList();
        await sheep.$store('AI').setAllFollowList();
        await sheep.$store('AI').setUserFamily();
      } else {
        await sheep.$store('AI').setDefaultAllSessionList();
        await sheep.$store('AI').setDefaultAllFollowList();
      }


    });

    onError((err) => {
      console.log('AppOnError:', err);
    });

    onShow(async () => {
      // #ifdef APP-PLUS
      // 获取urlSchemes参数
      const args = plus.runtime.arguments;
      if (args) {
      }

      // 获取剪贴板
      uni.getClipboardData({
        success: (res) => {
        },
      });
      // #endif
    });

    onHide(() => {
      console.log('拾亲页面隐藏=>');
    });

    onUnload(() => {
      console.log('拾亲页面卸载=>');
    });
</script>

<style lang="scss">
  @import '@/sheep/scss/index.scss';
</style>
